package com.xcs.wx;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.logging.Logger;

/**
 * @author xcs
 * @date 2023年12月21日 17时02分
 **/
@SpringBootApplication
@EnableTransactionManagement
public class WxDumpApplication {
    static Logger logger = Logger.getLogger(WxDumpApplication.class.getName());

    public static void main(String[] args) throws UnknownHostException {
        long startTime = System.currentTimeMillis();
        ConfigurableApplicationContext context = SpringApplication.run(WxDumpApplication.class, args);
        long endTime = System.currentTimeMillis();

        String port = context.getEnvironment().getProperty("server.port", "8080");
        String contextPath = context.getEnvironment().getProperty("server.servlet.context-path", "");
        String localHostAddress = InetAddress.getLocalHost().getHostAddress();

        String localUrl = "http://localhost:" + port + contextPath;
        String networkUrl = "http://" + localHostAddress + ":" + port + contextPath;

        logger.info(() -> "DONE successfully in " + (endTime - startTime) + "ms");
        logger.info(() -> "Time: " + new Date());
        logger.info(() -> "╔════════════════════════════════════════════════════╗");
        logger.info(() -> "║ App listening at:                                  ║");
        logger.info(() -> "║    > Local:   " + localUrl + "                      ");
        logger.info(() -> "║    > Network: " + networkUrl + "                    ");
        logger.info(() -> "║                                                    ║");
        logger.info(() -> "║ Now you can open browser with the above addresses↑ ║");
        logger.info(() -> "╚════════════════════════════════════════════════════╝");
    }
}
